﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.Windsor;

namespace Meqs.Logic
{
    public class MeqsCore : BaseSqlMapDao
    {
        #region DataBaseType

        public static DataBaseType DataBaseType
        {
            get
            {
                string description = SqlMap.DataSource.DbProvider.Description;
                string type = description.Split(',')[0];
                switch (type)
                {
                    case "Microsoft SQL Server":
                        return DataBaseType.MsSql;
                    case "Oracle":
                        return DataBaseType.Oracle;
                }
                return DataBaseType.MsSql;
            }
        }

        #endregion

        /// <summary>
        /// 注册容器
        /// </summary>
        /// <param name="windsorContainer"></param>
        public static void RegisterContainer(IWindsorContainer windsorContainer)
        {
            switch (DataBaseType)
            {
                case DataBaseType.MsSql:
                    RegisterSqlServer(windsorContainer);
                    break;
                case DataBaseType.Oracle:
                    RegisterOracle(windsorContainer);
                    break;
            }
        }

        private static void RegisterSqlServer(IWindsorContainer windsorContainer)
        {
            // DbManager
            windsorContainer.AddComponent("DbManagerLogic", typeof(Interface.IDbManagerLogic),
                                          typeof(Implement.MsSql.DbManagerLogic));
            // EvalReport
            windsorContainer.AddComponent("EvalReportLogic", typeof(Interface.IEvalReportLogic),
                                          typeof(Implement.MsSql.EvalReportLogic));
            // EvalSheets
            windsorContainer.AddComponent("EvalSheetsLogic", typeof(Interface.IEvalSheetsLogic),
                                          typeof(Implement.MsSql.EvalSheetsLogic));
            // EvalSettings
            windsorContainer.AddComponent("EvalSettingsLogic", typeof(Interface.IEvalSettingsLogic),
                                          typeof(Implement.MsSql.EvalSettingsLogic));

            //GlobalCauseInfoLogic
            windsorContainer.AddComponent("GlobalCauseInfoLogic", typeof(Interface.IGlobalCauseInfoLogic),
                                          typeof(Implement.MsSql.GlobalCauseInfoLogic));
        }

        private static void RegisterOracle(IWindsorContainer windsorContainer)
        {
            // DbManager
            windsorContainer.AddComponent("DbManagerLogic", typeof(Interface.IDbManagerLogic),
                                          typeof(Implement.Oracle.DbManagerLogic));
            // EvalReport
            windsorContainer.AddComponent("EvalReportLogic", typeof(Interface.IEvalReportLogic),
                                          typeof(Implement.Oracle.EvalReportLogic));
            // EvalSheets
            windsorContainer.AddComponent("EvalSheetsLogic", typeof(Interface.IEvalSheetsLogic),
                                          typeof(Implement.Oracle.EvalSheetsLogic));
            // EvalSettings
            windsorContainer.AddComponent("EvalSettingsLogic", typeof(Interface.IEvalSettingsLogic),
                                          typeof(Implement.Oracle.EvalSettingsLogic));

            //GlobalCauseInfoLogic
            windsorContainer.AddComponent("GlobalCauseInfoLogic", typeof(Interface.IGlobalCauseInfoLogic),
                                          typeof(Implement.Oracle.GlobalCauseInfoLogic));
        }
    }

    /// <summary>
    /// 数据库类型
    /// </summary>
    public enum DataBaseType
    {
        /// <summary>
        /// MsSql
        /// </summary>
        MsSql,
        /// <summary>
        /// Oracle
        /// </summary>
        Oracle
    }
}
